- params = request.params.except(:action, :controller, :model_name)
- query = params[:query]
- filter = params[:filter]
- sort = params[:sort]
- sort_reverse = params[:sort_reverse]
- path_method = params[:id] ? "history_show_path" : "history_index_path"

= form_tag("", method: "get", class: "search pjax-form form-inline") do
  .well
    .input-group
      %input.form-control.input-small{name: "query", type: "search", value: query, placeholder: "#{t("admin.misc.filter")}", class: 'input-small'}
      %span.input-group-btn
        %button.btn.btn-primary{type: "submit", :'data-disable-with' => "<i class='icon-white icon-refresh'></i> ".html_safe + t("admin.misc.refresh")}
          %i.icon-white.icon-refresh
          = t("admin.misc.refresh")
%table#history.table.table-striped.table-condensed
  %thead
    %tr
      - columns = []
      - columns << { property_name: "created_at", css_class: "created_at",link_text: t('admin.table_headers.created_at') }
      - columns << { property_name: "username",   css_class: "username",  link_text: t('admin.table_headers.username')   }
      - columns << { property_name: "item",       css_class: "item",      link_text: t('admin.table_headers.item')       } if @general
      - columns << { property_name: "message",    css_class: "message",   link_text: t('admin.table_headers.message')    }

      - columns.each do |column|
        - property_name = column[:property_name]
        - selected = (sort == property_name)
        - sort_direction = (sort_reverse ? "headerSortUp" : "headerSortDown" if selected)
        - sort_location = send(path_method, params.except("sort_reverse").merge(model_name: @abstract_model.to_param, sort: property_name).merge(selected && sort_reverse != "true" ? {sort_reverse: "true"} : {}))
        %th{class: "header pjax #{column[:css_class]} #{sort_direction if selected}", :'data-href' => sort_location}= column[:link_text]
  %tbody
    - @history.each_with_index do |object, index|
      %tr
        - unless object.created_at.nil?
          %td= l(object.created_at, format: :long, default: l(object.created_at, format: :long))
        %td= object.username
        - if @general
          - if o = @abstract_model.get(object.item)
            - label = o.send(@abstract_model.config.object_label_method)
            - if show_action = action(:show, @abstract_model, o)
              %td= link_to(label, url_for(action: show_action.action_name, model_name: @abstract_model.to_param, id: o.id), class: 'pjax')
            - else
              %td= label
          - else
            %td= "#{@abstract_model.config.label} ##{object.item}"
        %td= object.message.in?(['delete', 'new']) ? t("admin.actions.#{object.message}.done").capitalize : object.message

- unless params[:all] || !@history.respond_to?(:current_page)
  = paginate(@history, theme: 'ra-twitter-bootstrap', remote: true)
  = link_to(t("admin.misc.show_all"), send(path_method, params.merge(all: true)), class: "show-all btn pjax") unless (tc = @history.total_count) <= @history.size || tc > 100

